/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package usuario.control;

import usuario.frames.*;
import bibliinfo.FrameMain;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import usuario.model.Usuario;
import usuario.model.UsuarioDao;

/**
 *
 * @author Ar0n
 */
public class UserFameDadosAddEdit extends javax.swing.JInternalFrame {

    /**
     * Creates new form UserFameDadosEdit
     */
    public UserFameDadosAddEdit() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBEditar = new javax.swing.JButton();
        jBDados = new javax.swing.JButton();
        jBFechar = new javax.swing.JButton();

        jBEditar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365466392_notepad_(edit)_16x16.gif"))); // NOI18N
        jBEditar.setText("Editar");
        jBEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditarActionPerformed(evt);
            }
        });

        jBDados.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBDados.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365869813_restart-1.png"))); // NOI18N
        jBDados.setText("Dados Usuário");
        jBDados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBDadosActionPerformed(evt);
            }
        });

        jBFechar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365683699_window-close.png"))); // NOI18N
        jBFechar.setText("Fechar");
        jBFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBFecharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jBFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 385, Short.MAX_VALUE)
                .addComponent(jBEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
            .addGroup(layout.createSequentialGroup()
                .addGap(320, 320, 320)
                .addComponent(jBDados, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBDados, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBDadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDadosActionPerformed

        FrameMain.userFrameAdd.setVisible(false);
        FrameMain.userFrameAdd.setEstado(false);

        FrameMain.userFrameDados.setVisible(true);
        FrameMain.userFrameDados.setEstado(true);        
        FrameMain.formata(12);

    }//GEN-LAST:event_jBDadosActionPerformed

    private void jBFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBFecharActionPerformed
        FrameMain.userFrameAdd.setVisible(false);
        FrameMain.userFrameAdd.setEstado(false);
        
        FrameMain.userFrameMain.setVisible(true);
        FrameMain.userFrameMain.setEstado(true);
        FrameMain.formata(11);        
    }//GEN-LAST:event_jBFecharActionPerformed

    private void jBEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditarActionPerformed
        /**
     Esta parte do código impedir que o funcionario consiga editar os dados de um usuário deletado
     * e este método, ainda habilita o botão restaurar
     */    
        String rg = String.valueOf(FrameMain.userFrameDados.getRgAntigo());
        UsuarioDao dao = new UsuarioDao();
        List<Usuario> lista = dao.read(rg, 2);
        Usuario user = lista.get(0);              
        if(user.getAtivo() == false){            
            JOptionPane.showMessageDialog(FrameMain.userFrameAdd, "<html>O usuário foi deletado do sistema.<br />Para editar os seus dados ele deve ser <b color=\"blue\">restaurado</b></html>", "Bloqueio", 2);            
        }else{                                                
            FrameMain.userFrameDados.habilitaCampos();            
            FrameMain.userFrameAdd.escolheComp("update");                        
            if(FrameMain.userFrameAdd.jRBSim.isSelected() == true){
                FrameMain.userFrameAdd.habitaData(true);                                
            }
        }  
    }//GEN-LAST:event_jBEditarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBDados;
    private javax.swing.JButton jBEditar;
    private javax.swing.JButton jBFechar;
    // End of variables declaration//GEN-END:variables
    //Atributos
    private boolean estado ;
    //métodos
    public void setEstado(boolean estado){
        this.estado = estado;
    }
    public boolean getEstado(){
        return this.estado;
    }
}
